package cn.zktr.Personnel.controllers.ouyangpeng;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import cn.zktr.Personnel.common.EmailVerifier;
import cn.zktr.Personnel.common.IdCardVerifier;
import cn.zktr.Personnel.common.PhoneVerifier;
import cn.zktr.Personnel.model.pojos.PerIntention;
import cn.zktr.Personnel.model.pojos.PerPmsPot;
import cn.zktr.Personnel.model.pojos.PerPmsSex;
import cn.zktr.Personnel.model.pojos.PerRetRfs;
//import cn.zktr.Personnel.model.pojos.PerRetItt;
import cn.zktr.Personnel.model.pojos.PerRetRse;
import cn.zktr.Personnel.model.pojos.PerRetWAlt;
import cn.zktr.Personnel.model.service.ouyangpeng.RetRseService;
import cn.zktr.Personnel.model.service.ouyangpeng.RetWAltService;
import cn.zktr.Personnel.model.service.ouyangpeng.StorePicturesService;

@Controller
public class RetRseController {
	@Autowired
	private RetRseService retrseservice;
	@Autowired
	private RetWAltService retwalt;
	@Autowired
	private RetRseService retrse;
	private boolean validatedAllIdcard;
	@Autowired
	private StorePicturesService storeservice;
	
	@RequestMapping("oyp/recruit-jianli")
	
    public void jianli(HttpSession session) {

    }
	//sb
	@RequestMapping("jianliid")
	@ResponseBody
	private void iddss(HttpSession session,Integer altid,Integer rseid) {
		session.setAttribute("rseid", retrseservice.selectrseid(rseid));
		session.setAttribute("altid", retrseservice.selectjihuayqss(altid));
	}

    //填写简历信息
    @RequestMapping("oyp/personnel-txjianli")
    public String demo12(Model model) {
    	recruit(model);
		return "oyp/personnel-txjianli";
	}
	 public void recruit(Model model) {
			model.addAttribute("deptname", retwalt.selectDept());                 //部门
			model.addAttribute("empname", retwalt.selectemp());		              //员工
			model.addAttribute("potname", retwalt.selectpot());                   //职位
			model.addAttribute("potnames", retrse.selectyuangong());              //职级-职位列表
			model.addAttribute("yiyoupot", retrse.selectyiyouzy());               //已进行计划的职位
			model.addAttribute("fuzerennames", retrse.selectfuzenren());          //负责人
			model.addAttribute("jnxxname", retwalt.selectjineng());               //技能
			model.addAttribute("sexname", retrse.selectsex());                    //性别
			model.addAttribute("jihuanames", retrse.selectjihua());               //招聘计划
			model.addAttribute("xueliname", retrse.selectxueli());                //学历
			model.addAttribute("rsename", retrse.selerseAll());    				  //应聘人员 
	}
	//上传图片
    @RequestMapping("myimg") 
    @ResponseBody
    public String MyImage(MultipartFile fileImage) {
	    storeservice.saveFile(fileImage);
	    System.err.println("--------"+fileImage);
	    return "static/oyp/images/"+fileImage.getOriginalFilename();
    }
	@PostMapping("oyp/add-jianli") 
	@ResponseBody
	public String jianlixz(int jlaltid,String jlname,int jlsex,String jlage,String jlheight,
			String jlzhao,String jlidcard,String jlphone,String nation,String fromde,int jlzhiwei,
			String jlxinzi,String jlworkexp,String jlemail,int jlxueli,String jlschool,
			String jljishu,String jladddizhi,String jlworkexpss,String jlmepingjia) {
		System.err.println("-------------------"+jlzhao);
		if(!IdCardVerifier.isValidatedAllIdcard(jlidcard)) return "-1";//身份证
		if(!PhoneVerifier.isMobileNO(jlphone)) return "-2";//电话号码
		if(!EmailVerifier.EmailVerifiers(jlemail)) return "-3";//邮箱
		
		PerPmsSex jianlsex=new PerPmsSex();
		jianlsex.setSexid(jlsex);
		PerPmsPot pot=new PerPmsPot();
		pot.setPotid(jlzhiwei);
        PerRetRfs rfs=new PerRetRfs();
        rfs.setRfsid(jlxueli);
		
		PerRetRse rse=new PerRetRse();
		rse.setRsename(jlname);//姓名
		rse.setPerPmsSex(jianlsex);//性别
		rse.setRseage(jlage);//年龄
		rse.setRsehgt(jlheight);//身高
		rse.setRsehide(jlzhao);//照片
		rse.setRsecard(jlidcard);//身份证
		rse.setRsephome(jlphone);//电话
		rse.setRsemz(nation);//民族
		rse.setRsegj(fromde);//国籍
		rse.setPerPmsPot(pot);//职位
		rse.setRsexz(jlxinzi);//理想薪资
		rse.setRseexp(jlworkexp);//工作经验
		rse.setRseemail(jlemail);//邮箱
		rse.setPerRetRf(rfs);//学历
		rse.setRsebiye(jlschool);//毕业学校
		rse.setRsejs(jljishu);
		rse.setRsedizhi(jladddizhi);//地址
		rse.setRseexps(jlworkexpss);//工作经历
		rse.setRsejieshao(jlmepingjia);//自我评价
	
		PerRetWAlt alt=new PerRetWAlt();
		alt.setAltid(jlaltid);
		retrseservice.rsexz(rse,alt);
		
		return "0";//成功
	}

}
